package com.dhecp.project.finance.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhecp.common.utils.MessageUtils;
import com.dhecp.core.constant.DataFiltering;
import com.dhecp.core.utils.PageUtils;
import com.dhecp.project.common.service.impl.BaseModuleServiceImpl;
import com.dhecp.project.finance.domain.AccountCountForUser;
import com.dhecp.project.finance.domain.AccountDetailedForUser;
import com.dhecp.project.finance.mapper.AccountDetailedForUserMapper;
import com.dhecp.project.finance.service.AccountDetailedForUserService;
import com.dhecp.project.system.service.SysDictionaryForFieldService;

/**
 * 用户账户流水 服务层
 * @author DH-Xxj
 * @version 2022年10月11日
 */
@Service
public class AccountDetailedForUserServiceImpl extends BaseModuleServiceImpl implements AccountDetailedForUserService {

	@Autowired
	private AccountDetailedForUserMapper businessMapper;
	
	@Autowired
	private SysDictionaryForFieldService dictionaryForFieldService;
	
	/**
	 * 查询
	 * @param params
	 * @return List - AccountDetailedForUser
	 * @throws Exception
	 * @author DH-Xxj
	 */
	@Override
    public List<AccountDetailedForUser> queryList(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句
        if (params.get("field") == null || params.get("field") == ""){
			String orderBy = "userId asc";
			PageUtils.startPageOrder(orderBy);
		}else{
			PageUtils.startPage();	
		}
        return businessMapper.selectAll(params);
    }
	
	/**
	 * 查询汇总金额
	 * @param params
	 * @return List - AccountCountForUser
	 * @throws Exception
	 * @author DH-Xxj
	 */
	@Override
    public List<AccountCountForUser> queryCountList(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句
        if (params.get("field") == null || params.get("field") == ""){
			String orderBy = "userId asc";
			PageUtils.startPageOrder(orderBy);
		}else{
			PageUtils.startPage();	
		}
        return businessMapper.selectCountAll(params);
    }

    /**
     * 查询指定用户的汇总金额
     * @param userId 必要参数：用户编号
     * @return AccountCountForUser 实体
     * @throws Exception
     * @author DH-Xxj
     */
	@Override
    public AccountCountForUser queryCountByUserId(Map<String, Object> params) throws Exception {
        if (params.get("userId") == null || "".equals(params.get("userId"))){
        	throw new RuntimeException(MessageUtils.message("module.error.lack","用户编号【userId】"));
        }
        return businessMapper.selectCountByUserId(params.get("userId").toString());
    }

}
